﻿using Q.Spider.Core;
using Q.Spider.Common;
using Q.Spider.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;

namespace Q.Spider.Sample.Flow
{
    //淘票票结果保存示例
    public class TaoPiaoPiaoSave : FlowBase
    {
        public override Task RunAsync(FlowContext Context)
        {
            if (Request.Name != "淘票票")
            {
                return Task.CompletedTask;
            }

            var info = Request.GetProperties<Dictionary<string, string>>("info");
            if (info != null)
            {
                foreach (var item in info)
                {
                    //Save To Db
                    LogHelper.Logger.Info($"保存城市：{item} id等于{item.Key}");
                }
                Context.State = FlowContextHandelState.成功;
            }
            else
            {
                Context.State = FlowContextHandelState.错误;
            }
            return Task.CompletedTask;
        }
    }
}
